<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"  
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<TITLE>ERP SYSTEM</TITLE>
		<META name="description" content="ERP.COM"/>
		
		<!-- 引入外部js或css -->
	    <script th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}" type="text/javascript" ></script>
	    
	    <!-- 引入内部js或css -->
		<script th:src="${'/lib/layui/layui.js'}" type="text/javascript" charset="utf-8"></script>
		<script th:src="${'/js/xadmin.js'}" type="text/javascript"></script>
		<link th:href="${'/css/font.css'}" rel="stylesheet">
		<link th:href="${'/css/xadmin.css'}" rel="stylesheet">
	</head>
	
	<body class="login-bg">
		<div class="login" >
			<div class="message">企业资产管理系统-注册</div>
			<font  id="error" size="10" class="text-align:center" color="red"></font>
			<div id="darkbannerwrap"></div>
			<form method="post" class="layui-form">
				<input id="account" name="account" placeholder="用户名" type="text"
					class="layui-input">
				<hr class="hr15">
				<input id="password" name="password" placeholder="密码" type="password"
					class="layui-input">
				<hr class="hr15">
				<input lay-submit lay-filter="login" style="width: 100%;" id="registerButton" 
					type="button" value="注册"/>
				<hr class="hr20">
				<div class="layui-form-item">
				<div class="layui-form-item" pane="">
					<div style="float:right;margin-top: 10px;"><a href="/login">登录</a></div>
				</div>
			</form>
		</div>
	</body>
	<script>
		/*
		 * 用户注册
		 */
		$("#registerButton").bind("click", function() {
			var user = {};
			user.account = $("[name='account']").val();
			user.password = $("[name='password']").val();
			var layer = layui.layer;
			if (user.account.length<2) {
				layer.msg('昵称至少得2个字符啊',{icon: 0});
				return;
			}else if (user.password.length<6||user.password.length>12){
				layer.msg('密码必须6到12位',{icon: 0});
				return;
			}
			$.ajax({
				url : "/doRegister",
				type : "post",
				contentType: "application/json",
				data : JSON.stringify(user),
				success : function (data) {
					if (data.status == 200) {
						// todo
						location.href = "/login";
					} else {
						layer.msg(data.message, {icon: 0});
					}
				},
				error : function (data) {
					layer.msg(data.responseText, {icon: 0});
				}
			});
		});


	</script>
</html>